<!DOCTYPE html>
<html>
	<head>
		 <meta charset="utf-8">
		<meta charset="{CHARSET}">
		<title>分类</title>
		<link rel="stylesheet" href="css/cat.css" />
		<script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
		<script src="js/data.js" charset="utf-8"></script>
		 <script src="js/flexible.js"></script>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no, viewport-fit=cover">
	</head>
	<body>
		<div class="all">
			<div class="top"></div>
			<div class="cnt clearfix">
				<div class="sub_nav fl" id="leftnav"></div>
				<div class="cat_list fl" id="cat_list"></div>
			</div>
			<div class="bot"></div>
		</div>
	</body>
</html>

<script>
	console.log(data);
	
	var arrs = data.json.keywordAreas;
	
	for(var i = 0;i<arrs.length;i++){
		var a = arrs[i];
		var navLi = document.createElement("div");
		navLi.index = i;
		navLi.onclick = function(){
			loadCatData(this.index);
			clearNavLiClassName();
			this.className = "div_active";
		};
		if(i==0){
			navLi.className = "div_active";
		}
		navLi.innerHTML = a.areaName;
		leftnav.appendChild(navLi);
	}
	
	function clearNavLiClassName(){
		var divs = leftnav.getElementsByTagName("div");
		for(var i = 0;i<divs.length;i++){
			divs[i].className="";
		}	
	}
	
	loadCatData(0);
	
	function loadCatData(num){
         cat_list.innerHTML = "";
         var arrs2 = arrs[num].level1words;

         for(var j=0;j<arrs2.length;j++){
             var a2 = arrs2[j];
             var navLi = document.createElement("div");
             navLi.innerHTML = a2.keyword;
             navLi.style.fontWeight = "700";
             navLi.style.fontSize = "18px";
             cat_list.appendChild(navLi);
			var smallcatList = document.createElement("div");
			smallcatList.className = "smallcatList clearfix";
			var arrs3 = a2.level2words;
			for(var k =0;k<arrs3.length;k++){
				var a3 = arrs3[k];
				
				var catDiv = document.createElement("div");
				catDiv.className = "cat fl";
				
				catDiv.style.width = "30%";
				var imageDiv = document.createElement("img");
				imageDiv.src = "http:"+a3.imageUrl;
				imageDiv.style.width = "100%";
				var txtDiv = document.createElement("div");
				txtDiv.innerHTML = a3.keyword;
				
				txtDiv.onclick = function(){
					location = 'https://so.m.jd.com/ware/search.action?keyword='+this.innerHTML+'&searchFrom=category';
				};
				catDiv.appendChild(imageDiv);
				catDiv.appendChild(txtDiv);
				smallcatList.appendChild(catDiv);
			}
			cat_list.appendChild(smallcatList);
		}
	}
	
	window.onload = function(){
     
            var ww = document.body.clientWidth || document.documentElement.clientWidth;
     
            var wh = document.body.clientHeight || document.documentElement.clientHeight;
            
            var r = wh / ww;
           
            var cntHeight = r*10-2;
            cnt.style.height = cntHeight+"rem";
        }
	
</script>
